﻿using System;
using System.Collections.Generic;
using System.Linq;
namespace LVYAN.Utils
{
    public class AIConfig
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private List<ConfigModel> GetConfigList()
        {
            return JsonToModelService.GetModelByPath<List<ConfigModel>>($"Config/Config.json");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ConfigReponseModel GetConfigModel(string ClassName,string MethodName)
        {
            var Hour = DateTime.Now.Hour;
            var Name = $"{ClassName}.{MethodName}";
            var Model = this.GetConfigList().Where(t => t.StartHour <= Hour && t.EndHour > Hour).OrderBy(t => t.Level).FirstOrDefault();
            if (Model == null)return new ConfigReponseModel { Cache = 5, IsConsole = false, IsLog = false, AppCache=2024 };
            var Method= Model.CacheList.FirstOrDefault(t => t.Name == Name);
            if (Method==null) return new ConfigReponseModel { Cache = 5, IsConsole = Model.IsConsole, IsLog = Model.IsLog, AppCache = Model.AppCache };
            return new ConfigReponseModel { Cache = Method.Cache, IsConsole = Model.IsConsole, IsLog = Model.IsLog, AppCache = Model.AppCache };
        }
    }
}
